package manager;

import java.util.ArrayList;

import entity.Course;

public class CoursePreRequisiteMgr {
	DatabaseMgr dbMgr;

	public CoursePreRequisiteMgr() {
		dbMgr = new DatabaseMgr();
	}

	public void addPreRequisiteForCourse(String prerequisiteCode,
			String courseCode) {

		String sql = "insert into prerequisite (courseCode, prerequisiteCode) values (?,?) ";
		dbMgr.openAndUpdateAndClose(sql, courseCode, prerequisiteCode);
	}

	public ArrayList<Course> retrieveAllCoursesWithPrerequisite() {
		String sql = "select * from course inner join prerequisite on "
				+ "course.courseCode = prerequisite.coursecode";

		return RetrieveCourseUtil.retrieveMultipleCoursesForQuery(dbMgr, sql);
	}

	public ArrayList<Course> retrievePreRequisitesForCourse(String courseCode) {

		String sql = "select * from course inner join prerequisite on "
				+ "course.courseCode = prerequisite.coursecode where course.courseCode=?";

		return RetrieveCourseUtil.retrieveMultipleCoursesForQuery(dbMgr, sql,
				courseCode);
	}

	public void deleteAllPreRequisites() {
		dbMgr.openAndUpdateAndClose("delete from prerequisite");
	}

}
